home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / contrib / pdcurs22 / samples / ptest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  7.2 KB  |  355 lines

  1. /*
  2. ***************************************************************************
  3. * This file comprises part of PDCurses. PDCurses is Public Domain software.
  4. * You may use this code for whatever purposes you desire. This software
  5. * is provided AS IS with NO WARRANTY whatsoever.
  6. * Should this software be used in another application, an acknowledgement
  7. * that PDCurses code is used would be appreciated, but is not mandatory.
  8. *
  9. * Any changes which you make to this software which may improve or enhance
  10. * it, should be forwarded to the current maintainer for the benefit of 
  11. * other users.
  12. *
  13. * The only restriction placed on this code is that no distribution of
  14. * modified PDCurses code be made under the PDCurses name, by anyone
  15. * other than the current maintainer.
  16. * See the file maintain.er for details of the current maintainer.
  17. ***************************************************************************
  18. */
  19. /*+-------------------------------------------------------------------------
  20.     ptest.c
  21. --------------------------------------------------------------------------*/
  22.  
  23. #ifdef PDCDEBUG
  24. char *rcsid_ptest  = "$Id$";
  25. #endif
  26.  
  27. #include <curses.h>
  28. #include "panel.h"
  29.  
  30. #if defined(XCURSES)
  31.     char *XCursesProgramName = "ptest";
  32. #endif
  33.  
  34. PANEL *p1;
  35. PANEL *p2;
  36. PANEL *p3;
  37. PANEL *p4;
  38. PANEL *p5;
  39. WINDOW *w1;
  40. WINDOW *w2;
  41. WINDOW *w3;
  42. WINDOW *w4;
  43. WINDOW *w5;
  44.  
  45. #define getmaxx(w)    (w)->_maxx
  46. #define getmaxy(w)    (w)->_maxy
  47. #define    nap(x)        usleep(1000*x)
  48.  
  49. long nap_msec = 1;
  50.  
  51. char *mod[] = 
  52. {
  53.     "test ",
  54.     "TEST ",
  55.     "(**) ",
  56.     "*()* ",
  57.     "<--> ",
  58.     "LAST "
  59. };
  60.  
  61. /*+-------------------------------------------------------------------------
  62.     wait_a_while(msec)
  63. --------------------------------------------------------------------------*/
  64. void
  65. wait_a_while(msec)
  66. long msec;
  67. {
  68.     getchar();
  69.     return;
  70. }    /* end of wait_a_while */
  71.  
  72. /*+-------------------------------------------------------------------------
  73.     saywhat(text)
  74. --------------------------------------------------------------------------*/
  75. void
  76. saywhat(text)
  77. char *text;
  78. {
  79. int y,x;
  80.  
  81.     wmove(stdscr,LINES - 1,0);
  82.     wprintw(stdscr,"%-20.20s",text);
  83.  
  84. }    /* end of saywhat */
  85.  
  86. /*+-------------------------------------------------------------------------
  87.     mkpanel(rows,cols,tly,tlx) - alloc a win and panel and associate them
  88. --------------------------------------------------------------------------*/
  89. PANEL *
  90. mkpanel(rows,cols,tly,tlx)
  91. int rows;
  92. int cols;
  93. int tly;
  94. int tlx;
  95. {
  96. WINDOW *win = newwin(rows,cols,tly,tlx);
  97. PANEL *pan;
  98.  
  99.     if(!win)
  100.         return((PANEL *)0);
  101.     if(pan = new_panel(win))
  102.         return(pan);
  103.     delwin(win);
  104.     return((PANEL *)0);
  105. }    /* end of mkpanel */
  106.  
  107. /*+-------------------------------------------------------------------------
  108.     rmpanel(pan)
  109. --------------------------------------------------------------------------*/
  110. void
  111. rmpanel(pan)
  112. PANEL *pan;
  113. {
  114. WINDOW *win = pan->win;
  115.     del_panel(pan);
  116.     delwin(win);
  117. }    /* end of rmpanel */
  118.  
  119. /*+-------------------------------------------------------------------------
  120.     pflush()
  121. --------------------------------------------------------------------------*/
  122. void
  123. pflush()
  124. {
  125.     update_panels();
  126.     doupdate();
  127. }    /* end of pflush */
  128.  
  129. /*+-------------------------------------------------------------------------
  130.     fill_panel(win)
  131. --------------------------------------------------------------------------*/
  132. fill_panel(pan)
  133. PANEL *pan;
  134. {
  135. WINDOW *win = pan->win;
  136. char num = *(pan->user + 1);
  137. int y,x;
  138.  
  139.     box(win, 0, 0);  
  140.     wmove(win,1,1);
  141.     wprintw(win,"-pan%c-",num);
  142.     for(y = 2; y < getmaxy(win) - 1; y++)
  143.     {
  144.         for(x = 1; x < getmaxx(win) - 1; x++)
  145.         {
  146.             wmove(win,y,x);
  147.             waddch(win,num);
  148.         }
  149.     }
  150. }    /* end of fill_panel */
  151.  
  152. /*+-------------------------------------------------------------------------
  153.     main(argc,argv)
  154. --------------------------------------------------------------------------*/
  155. main(argc,argv)
  156. int argc;
  157. char **argv;
  158. {
  159. int itmp;
  160. register y,x;
  161. long atol();
  162.  
  163.     if((argc > 1) && atol(argv[1]))
  164.         nap_msec = atol(argv[1]);
  165.  
  166.     initscr();
  167.  
  168.     for(y = 0; y < LINES - 1; y++)
  169.     {
  170.         for(x = 0; x < COLS; x++)
  171.             wprintw(stdscr,"%d",(y + x) % 10);
  172.     }
  173.     for(y = 0; y < 5; y++)
  174.     {
  175.         p1 = mkpanel(10,10,0,0);
  176.         w1 = panel_window(p1);
  177.         set_panel_userptr(p1,"p1");
  178.  
  179.         p2 = mkpanel(14,14,5,5);
  180.         w2 = panel_window(p2);
  181.         set_panel_userptr(p2,"p2");
  182.  
  183.         p3 = mkpanel(6,8,12,12);
  184.         w3 = panel_window(p3);
  185.         set_panel_userptr(p3,"p3");
  186.  
  187.         p4 = mkpanel(10,10,10,30);
  188.         w4 = panel_window(p4);
  189.         set_panel_userptr(p4,"p4");
  190.  
  191.         p5 = mkpanel(10,10,13,37);
  192.         w5 = panel_window(p5);
  193.         set_panel_userptr(p5,"p5");
  194.  
  195.         fill_panel(p1);
  196.         fill_panel(p2);
  197.         fill_panel(p3);
  198.         fill_panel(p4);
  199.         fill_panel(p5);
  200.         hide_panel(p4);
  201.         hide_panel(p5);
  202.         pflush();
  203.         wait_a_while(nap_msec);
  204.  
  205.         saywhat("h3 s1 s2 s4 s5;");
  206.         move_panel(p1,0,0);
  207.         hide_panel(p3);
  208.         show_panel(p1);
  209.         show_panel(p2);
  210.         show_panel(p4);
  211.         show_panel(p5);
  212.         pflush();
  213.         wait_a_while(nap_msec);
  214.  
  215.         saywhat("s1;");
  216.         show_panel(p1);
  217.         pflush();
  218.         wait_a_while(nap_msec);
  219.  
  220.         saywhat("s2;");
  221.         show_panel(p2);
  222.         pflush();
  223.         wait_a_while(nap_msec);
  224.  
  225.         saywhat("m2;");
  226.         move_panel(p2,10,10);
  227.         pflush();
  228.         wait_a_while(nap_msec);
  229.  
  230.         saywhat("s3;");
  231.         show_panel(p3);
  232.         pflush();
  233.         wait_a_while(nap_msec);
  234.  
  235.         saywhat("m3;");
  236.         move_panel(p3,5,5);
  237.         pflush();
  238.         wait_a_while(nap_msec);
  239.  
  240.         saywhat("b3;");
  241.         bottom_panel(p3);
  242.         pflush();
  243.         wait_a_while(nap_msec);
  244.  
  245.         saywhat("s4;");
  246.         show_panel(p4);
  247.         pflush();
  248.         wait_a_while(nap_msec);
  249.  
  250.         saywhat("s5;");
  251.         show_panel(p5);
  252.         pflush();
  253.         wait_a_while(nap_msec);
  254.  
  255.         saywhat("t3;");
  256.         top_panel(p3);
  257.         pflush();
  258.         wait_a_while(nap_msec);
  259.  
  260.         saywhat("t1;");
  261.         top_panel(p1);
  262.         pflush();
  263.         wait_a_while(nap_msec);
  264.  
  265.         saywhat("t2;");
  266.         top_panel(p2);
  267.         pflush();
  268.         wait_a_while(nap_msec);
  269.  
  270.         saywhat("t3;");
  271.         top_panel(p3);
  272.         pflush();
  273.         wait_a_while(nap_msec);
  274.  
  275.         saywhat("t4;");
  276.         top_panel(p4);
  277.         pflush();
  278.         wait_a_while(nap_msec);
  279.  
  280.         for(itmp = 0; itmp < 6; itmp++)
  281.         {
  282.             saywhat("m4;");
  283.             wmove(w4,3,1);
  284.             waddstr(w4,mod[itmp]);
  285.             move_panel(p4,4,itmp*10);
  286.             wmove(w5,4,1);
  287.             waddstr(w5,mod[itmp]);
  288.             pflush();
  289.             wait_a_while(nap_msec);
  290.             saywhat("m5;");
  291.             wmove(w4,4,1);
  292.             waddstr(w4,mod[itmp]);
  293.             move_panel(p5,7,(itmp*10) + 6);
  294.             wmove(w5,3,1);
  295.             waddstr(w5,mod[itmp]);
  296.             pflush();
  297.             wait_a_while(nap_msec);
  298.         }
  299.  
  300.         saywhat("m4;");
  301.         move_panel(p4,4,itmp*10);
  302.         pflush();
  303.         wait_a_while(nap_msec);
  304.  
  305.         saywhat("t5;");
  306.         top_panel(p5);
  307.         pflush();
  308.         wait_a_while(nap_msec);
  309.  
  310.         saywhat("t2;");
  311.         top_panel(p2);
  312.         pflush();
  313.         wait_a_while(nap_msec);
  314.  
  315.         saywhat("t1;");
  316.         top_panel(p1);
  317.         pflush();
  318.         wait_a_while(nap_msec);
  319.  
  320.         saywhat("d2;");
  321.         rmpanel(p2);
  322.         pflush();
  323.         wait_a_while(nap_msec);
  324.  
  325.         saywhat("h3;");
  326.         hide_panel(p3);
  327.         pflush();
  328.         wait_a_while(nap_msec);
  329.  
  330.         saywhat("d1;");
  331.         rmpanel(p1);
  332.         pflush();
  333.         wait_a_while(nap_msec);
  334.  
  335.         saywhat("d4; ");
  336.         rmpanel(p4);
  337.         pflush();
  338.         wait_a_while(nap_msec);
  339.  
  340.         saywhat("d5; ");
  341.         rmpanel(p5);
  342.         pflush();
  343.         wait_a_while(nap_msec);
  344.         if(nap_msec == 1)
  345.             break;
  346.         nap_msec = 100L;
  347.     }
  348.     endwin();
  349.     exit(0);
  350. }    /* end of main */
  351.  
  352. /* vi: set tabstop=4 shiftwidth=4: */
  353. /* end of ptest.c */
  354.